package com.azkj.album.presenter;

import android.widget.TextView;

import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.net.exception.ApiException;
import com.azkj.album.view.base.BasePresenter;
import com.azkj.album.view.iview.ISmsView;

import java.util.Map;

public class SendSmsPresenter extends BasePresenter {

    private final ISmsView iSmsView;


    public SendSmsPresenter(ISmsView iSmsView) {
        this.iSmsView = iSmsView;
    }


    public void sendSMS(Map<String, Object> body) {

        NetworkMaster.getInstance().getCommonService().getSmsCode(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                if (jsonObj.getCode() == 1) {
                    iSmsView.sendSmsSuccess(null);
                } else {
                    iSmsView.sendSmsFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iSmsView.sendSmsFail(apiException.errorInfo.error);
            }

        });
    }

    public void checkSmsCode(Map<String, Object> body) {

        NetworkMaster.getInstance().getCommonService().checkSmsCode(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                if (jsonObj.getCode() == 1) {
                    iSmsView.checkSmsSuccess();
                } else {
                    iSmsView.checkSmsFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iSmsView.checkSmsFail(apiException.errorInfo.error);
            }

        });
    }

    public void sendSMS(Map<String, Object> body, TextView textView) {
        NetworkMaster.getInstance().getCommonService().getSmsCode(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                if (jsonObj.getCode() == 1) {
                    iSmsView.sendSmsSuccess(textView);
                } else {
                    iSmsView.sendSmsFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iSmsView.sendSmsFail(apiException.errorInfo.error);
            }

        });
    }

}
